package it.antonio.ilpizze.mock.verification;

import java.util.List;

import it.antonio.ilpizze.aop.Invocation;
import it.antonio.ilpizze.mock.ArgumentMatcher;
import it.antonio.ilpizze.mock.Verification;
import it.antonio.ilpizze.reflection.MethodAccessor;

public class AtLeastVerification implements Verification{

private int times;
	
	public AtLeastVerification(int times) {
		this.times = times;
	}

	@Override
	public String verify(MethodAccessor current, List<ArgumentMatcher> matchers, List<Invocation> allInvocation) {
		int times = 0;
		for(Invocation invocation: allInvocation){
			
			if(current.equals(invocation.getMethod())){
				
				if(invocation.getArguments().length == 0){
					times++;
				} else {
					for(int i = 0; i < matchers.size(); i++){
						if(matchers.get(i).matches(invocation.getArguments()[i])){
							times++;
						}
					}	
				}
			}
			
		}
		if(this.times <= times){
			return null;
		} else {
			return "Expected at least " + this.times + " times instead of " + times;
		}
	}

}
